package user

import (
	"context"
	"github.com/jinzhu/copier"
	"github.com/pkg/errors"
	"yangming-college/app/usercenter/cmd/v1/api/internal/svc"
	"yangming-college/app/usercenter/cmd/v1/api/internal/types"
	"yangming-college/app/usercenter/cmd/v1/rpc/usercenter"

	"github.com/zeromicro/go-zero/core/logx"
)

type DetailLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DetailLogic {
	return &DetailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DetailLogic) Detail(req *types.UserInfoReq) (resp *types.UserInfoResp, err error) {
	accountDetail, err := l.svcCtx.UsercenterRpc.GetUserDetail(l.ctx, &usercenter.UserInfoRequest{
		Id: req.Id,
	})
	if err != nil {
		return nil, errors.Wrapf(err, "rpc获取用户详情失败")
	}
	var account types.Account
	copier.Copy(&account, accountDetail.Account)
	return &types.UserInfoResp{
		Account: account,
	}, nil
}
